package com.base.server.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.base.server.sys.dao.SysDictTypeDao;
import com.base.server.sys.pojo.SysDictType;
import com.base.server.sys.service.SysDictTypeService;
import com.system.comm.model.Page;
import com.system.handle.model.ResponseCode;
import com.system.handle.model.ResponseFrame;

/**
 * sys_dict_type的Service
 * @author admin
 * @date 2019-08-05 16:30:02
 * @version V1.0.0
 */
@Component
public class SysDictTypeServiceImpl implements SysDictTypeService {

	@Autowired
	private SysDictTypeDao sysDictTypeDao;
	
	/**
	 * 保存或修改
	 * @param sysDictType
	 * @return
	 */
	@Override
	public ResponseFrame saveOrUpdate(SysDictType sysDictType) {
		ResponseFrame frame = new ResponseFrame();
		SysDictType org = get(sysDictType.getCode());
		if(org == null) {
			sysDictTypeDao.save(sysDictType);
		} else {
			sysDictTypeDao.update(sysDictType);
		}
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}
	
	/**
	 * 根据code获取对象
	 * @param code
	 * @return
	 */
	@Override
	public SysDictType get(String code) {
		return sysDictTypeDao.get(code);
	}

	/**
	 * 分页获取对象
	 * @param sysDictType
	 * @return
	 */
	@Override
	public ResponseFrame pageQuery(SysDictType sysDictType) {
		sysDictType.setDefPageSize();
		ResponseFrame frame = new ResponseFrame();
		int total = sysDictTypeDao.findSysDictTypeCount(sysDictType);
		List<SysDictType> data = null;
		if(total > 0) {
			data = sysDictTypeDao.findSysDictType(sysDictType);
		}
		Page<SysDictType> page = new Page<SysDictType>(sysDictType.getPage(), sysDictType.getSize(), total, data);
		frame.setBody(page);
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}
	
	/**
	 * 根据code删除对象
	 * @param code
	 * @return
	 */
	@Override
	public ResponseFrame delete(String code) {
		ResponseFrame frame = new ResponseFrame();
		sysDictTypeDao.delete(code);
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}
}